package com.cwj.film.controller;


import com.cwj.common.domain.film;
import com.cwj.common.vo.Result;
import com.cwj.common.vo.film.indexSo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class indexController {

    @Resource
    private com.cwj.film.service.inter.index index;
    @Resource
    private ObjectMapper objectMapper;
    @PostMapping("/GetFilmBigPictList")
    private Result GetFilmBigPictList(indexSo indexSo) throws InvocationTargetException, IllegalAccessException {

        List<film> films = index.GetFilmBigPictList(indexSo.getSize());

        return Result.normal(films,"返回List集合 元素是film对象  属性值 title type _1740x1036pict");
    }
    @PostMapping("/GetFilmLittlePictList")
    private Result GetFilmLittlePictList(indexSo indexSo) throws InvocationTargetException, IllegalAccessException {

        List<film> films = index.GetFilmLittlePictList(indexSo.getSize());

        return Result.normal(films,"返回list集合 元素是film对象 属性值  title type _540x488pict");
    }
    @PostMapping("/GetFilmTitleMapByTypeMap")
    private Result GetFilmTitleMapByTypeMap(indexSo indexSo) throws JsonProcessingException {
        Map<String,Integer> map = objectMapper.readValue(indexSo.getTypeMap(), new TypeReference<>() {});

        Map<String, List<film>> listMap = index.GetFilmTitleMapByTypeMap(map);

        return Result.normal(listMap,"map集合 key为影片类型  value为影片list集合");
    }
}
